Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix connection flush #130

Merged
merged 5 commits into from
Feb 25, 2022
Merged

Fix connection flush #130

merged 5 commits into from
Feb 25, 2022

Conversation

appaquet
Copy link
Contributor

See the full conversation here: libp2p/rust-libp2p#2461

The bump to Yamux 0.10 in libp2p broke the wasm-ext transport (used for WebSocket transport in WebAssembly). It turns out that the wasm-ext implementation makes it more prone to yield a Pending on a poll_next (see this). When used in conjunction with Noise, a frame may get buffered and only written to the underlying I/O stream when flushing it (see this)

In #112, flushing is no longer awaited, but instead, is called at each iteration of the next loop in Connection (see this). Unfortunately, when using wasm-ext with Noise, frames may never get written until the next iteration is triggered by another event (incoming frame or stream/control events).

As discussed in libp2p's issue, a fix is to make sure that flushing the I/O stream gets progressed in the main loop. I also think that flush_nowait is not required anymore since flushing is now actively done in the loop.

Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, thank you for digging so deep into this!

return Poll::Ready(res);
}

if let Poll::Ready(Err(err)) = socket.poll_flush_unpin(cx) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we assume that for all implementations of Sink poll_flush_unpin is cheap? If not, we could stop calling poll_flush_unpin once it returns Poll::Ready(Ok(())).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense. But we need to make sure to reset every time we write to the underlying IO

src/connection.rs Outdated Show resolved Hide resolved
@appaquet
Copy link
Contributor Author

@mxinden Updated. I don't know if you had something else in mind, but it does the trick.

Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @appaquet. I will prepare a release candidate to test on larger deployments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants